package com.leo.blog.config;


import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

/**
 * Created by Administrator on 2018/5/11.
 */
public class ApplicationHome {
    public Environment environment;
    public ConfigurableApplicationContext context;
    private static ApplicationHome applicationHome=new ApplicationHome();
//    public HashMap<String,List<SysCfgSettingEntity>> mapSpInfEntity=new HashMap<String,List<SysCfgSettingEntity>>();
    public static String getApplicationHome(){
        String applicationHome = System.getProperty("application_home");
        String application_home = applicationHome == null ? System.getenv("application_home") : applicationHome;
        application_home= application_home==null||application_home.trim().equalsIgnoreCase("")?System.getProperty("user.dir"):application_home;
        return application_home;
    }


    public static ApplicationHome getOne(){
        return applicationHome;
    }
    public static String getApplicationLog(){
        return getApplicationHome()+"/logs/";
    }

    public static String getApplicationConfig(){
        return getApplicationHome()+"/config/";
    }

    public static String getApplicationLogConfigFile(){
        return getApplicationHome()+"/config/logback.xml";
    }
    public void init(ApplicationContext applicationContext){

        environment= applicationContext.getEnvironment();
        context=(ConfigurableApplicationContext) applicationContext;

//        CommonDataApiNoTransDao commonDataApiDao=
//                applicationContext.getBean(CommonDataApiNoTransDao.class);
//        List<SysCfgSettingEntity> sysCfgSettingEntities=
//                commonDataApiDao.getScrollData(SysCfgSettingEntity.class).getResultlist();
//        for (int i = 0; i < sysCfgSettingEntities.size(); i++) {
//            SysCfgSettingEntity sysCfgSettingEntity = sysCfgSettingEntities.get(i);
//            List<SysCfgSettingEntity> sysCfgSettingEntitiesTmp=mapSpInfEntity.get(sysCfgSettingEntity.getItemcode());
//            if(sysCfgSettingEntitiesTmp==null){
//                sysCfgSettingEntitiesTmp=new LinkedList<>();
//                mapSpInfEntity.put(sysCfgSettingEntity.getItemcode(),sysCfgSettingEntitiesTmp);
//            }
//            sysCfgSettingEntitiesTmp.add(sysCfgSettingEntity);
//        }


    }
//    public  List<SysCfgSettingEntity> getSysCfgSettingEntity(String itemcode){
//        return mapSpInfEntity.get(itemcode);
//    }
}
